package sedev.shopping.business;

import sedev.shopping.data.LoaiSanPhamDAO;
import sedev.shopping.entities.ListLoaiSanPham;
import sedev.shopping.entities.LoaiSanPham;
import sedev.shopping.util.Paging;
import sedev.shopping.util.SedevUtil;

public class LoaiSanPhamService {
	
	public static boolean addData(LoaiSanPham data){
		LoaiSanPhamDAO dao = new LoaiSanPhamDAO();
		return dao.addData(data);
	}
	
	public static boolean updateData(LoaiSanPham data){
		LoaiSanPhamDAO dao = new LoaiSanPhamDAO();
		return dao.updateData(data);
	}
	
	public static boolean removeData(long id){
		LoaiSanPhamDAO dao = new LoaiSanPhamDAO();
		return dao.removeData(id);
	}
	
	public static LoaiSanPham getData(long id){
		LoaiSanPhamDAO dao = new LoaiSanPhamDAO();
		return dao.getData(id);		
	}
		
	public static ListLoaiSanPham getListDataByAll(Paging paging, SedevUtil.ModeDisplay mode_display){
		StringBuilder field = new StringBuilder();
		field.append(LoaiSanPham.Properties.id.name());
		field.append(",").append(LoaiSanPham.Properties.ten.name());
		field.append(",").append(LoaiSanPham.Properties.hien_thi.name());
		field.append(",").append(LoaiSanPham.Properties.ngay_dang.name());
	
		StringBuilder condition = new StringBuilder();
		condition.append("1 AND 1");
		switch (mode_display) {
			case Display:
				condition.append(" AND ").append(LoaiSanPham.Properties.hien_thi.name()).append("= 1");
				break;
			case Hide:
				condition.append(" AND ").append(LoaiSanPham.Properties.hien_thi.name()).append("= 0");
				break;
			default:
				break;
		}
		
		StringBuilder order = new StringBuilder();
		order.append(LoaiSanPham.Properties.ngay_dang.name()).append(" ").append(SedevUtil.Order.ASC);
		
		LoaiSanPhamDAO dao = new LoaiSanPhamDAO();
		return dao.getListData(field.toString(), condition.toString(), order.toString(), paging);
	}
	
	public static ListLoaiSanPham getListDataByUser(long user_id, Paging paging, SedevUtil.ModeDisplay mode_display){
		StringBuilder field = new StringBuilder();
		field.append(LoaiSanPham.Properties.id.name());
		field.append(",").append(LoaiSanPham.Properties.ten.name());
		field.append(",").append(LoaiSanPham.Properties.thuoc_tinh.name());
		field.append(",").append(LoaiSanPham.Properties.hien_thi.name());
		field.append(",").append(LoaiSanPham.Properties.ngay_dang.name());
	
		StringBuilder condition = new StringBuilder();
		condition.append("1 AND 1");
		condition.append(" AND ").append(LoaiSanPham.Properties.user_id).append("=").append(user_id);
		switch (mode_display) {
			case Display:
				condition.append(" AND ").append(LoaiSanPham.Properties.hien_thi.name()).append("= 1");
				break;
			case Hide:
				condition.append(" AND ").append(LoaiSanPham.Properties.hien_thi.name()).append("= 0");
				break;
			default:
				break;
		}
		
		StringBuilder order = new StringBuilder();
		order.append(LoaiSanPham.Properties.ngay_dang.name()).append(" ").append(SedevUtil.Order.ASC);		
		
		LoaiSanPhamDAO dao = new LoaiSanPhamDAO();
		return dao.getListData(field.toString(), condition.toString(), order.toString(), paging);
	}
}
